package cn.xuchunh.campusbbs.adapter;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import java.util.ArrayList;
import java.util.List;

import cn.xuchunh.campusbbs.base.BaseFragment;

/**
 * Created by XuChunH on 2015/9/11.
 */
public class HomePageAdapter extends FragmentPagerAdapter {

    private List<BaseFragment> fragmentList = new ArrayList<>();
    private List<String> titleList = new ArrayList<>();

    public HomePageAdapter(FragmentManager fm) {
        this(fm, null, null);
    }

    public HomePageAdapter(FragmentManager fm, List<BaseFragment> fragmentList, List<String> titleList) {
        super(fm);
        if (fragmentList != null && fragmentList.size() > 0) {
            this.fragmentList = fragmentList;
        }
        if (titleList != null && titleList.size() > 0) {
            this.titleList = titleList;
        }
    }

    @Override
    public Fragment getItem(int position) {
        return fragmentList.get(position);
    }

    @Override
    public int getCount() {
        return fragmentList.size();
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return titleList.get(position);
    }

    public void setFragmentList(List<BaseFragment> fragmentList) {
        this.fragmentList = fragmentList;
    }
}
